using System;
using System.Collections.Generic;

using IGlobalist.Cms.Model;
using IGlobalist.Cms.DataAccess;

namespace IGlobalist.Cms.Bll
{
    public class ClassController : BaseController
    {
        
        public static IList<ICmsClass> GetClassListByClassTypeID(short classTypeID)
        {
            bool add = true;
            IList<ICmsClass> list = new List<ICmsClass>();
            IList<ICmsClass> listResult = new List<ICmsClass>();
            list =_Ds.GetClassListByClassTypeID(classTypeID);

            foreach (CmsClass c in list)
            {
                for (int i = 0; i < c.PropertyList.Count; i++)
                {
                    if ((Convert.ToString(c.PropertyList[i].Name) == "TypeClass") && (Convert.ToString(c.PropertyList[i].Value) == "Forum"))
                    {
                        add = false;
                        break;
                    }
                }
                if (add == true)
                {
                    listResult.Add(c);
                }
                else
                    add = true;
            }
            return listResult;
        }

        public static IList<ICmsClass> GetClassListByClassTypeID(short classTypeID, bool forum)
        {
           
            return _Ds.GetClassListByClassTypeID(classTypeID);

        }

        public static ICmsClass GetClassByUsageType(short classTypeID, UsageType usageType)
        {
            IList<ICmsClass> list = GetClassListByClassTypeID(classTypeID);
            foreach (ICmsClass clazz in list)
            {
                if (clazz.UsageType == usageType)
                {
                    return clazz;
                }
            }
            return null;
        }

        public static ICmsClass GetClass(long id)
        {
            return _Ds.GetClass(id);
        }

        public static ICmsClass GetClassByName(string name)
        {
            return _Ds.GetClassByName(name);
        }

        public static long InsertClass(ICmsClass clazz)
        {            
            return _Ds.InsertClass(clazz);
        }

        public static void UpdateClass(ICmsClass clazz)
        {
            _Ds.UpdateClass(clazz);
        }

        public static void DeleteClass(long id)
        {
            _Ds.DeleteClass(id);
        }
    }
}
